﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Dashboard/Dashboard.Master" AutoEventWireup="true" CodeBehind="Categories.aspx.cs" Inherits="JamesThew.Dashboard.Categories" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="Main" runat="server">
    <h2>Categories</h2>

    <div class="row">
    <form id="categories" runat="server">
        <div class="span4">
        
        <asp:Label ID="lblAddNewCategory" runat="server" Text="Label">Add New Category</asp:Label>
            <fieldset>
                <div class="control-group">
                  <label class="control-label" for="Main_txtCatName">Name</label>
                  <div class="controls">
                     <asp:TextBox ID="txtCatName" CssClass="input-xlarge" runat="server"></asp:TextBox>
                     <p class="help-block">The name is how it appears on your site.</p>
                  </div>
                </div><!--control-group-->

                <div class="control-group">
                  <label class="control-label" for="Main_ddParent">Parent</label>
                  <div class="controls">
                      <asp:DropDownList ID="ddParent" runat="server" DataSourceID="SqlDataSource2" 
                          DataTextField="CategoryName" DataValueField="CategoryID" AppendDataBoundItems="true">
                          <asp:ListItem Selected="True" Value="0">None</asp:ListItem>
                      </asp:DropDownList>
                     <p class="help-block">Categories, unlike tags, can have a hierarchy. You might have a Jazz category, and under that have children categories for Bebop and Big Band. Totally optional.
</p>
                  </div>
                </div><!--control-group-->

               <div class="control-group">
                  <label class="control-label" for="Main_txtDescription">Description</label> 

                  <div class="controls">
                    <asp:TextBox ID="txtDescription" CssClass="input-xlarge" runat="server" TextMode="MultiLine"></asp:TextBox>
                     <p class="help-block">The description is not prominent by default; however, some themes may show it.
</p>
                  </div>
                </div><!--control-group-->

             <div class="form-actions">
                    <asp:Button ID="btnAddCategory" runat="server" CssClass="btn btn-primary" 
                        Text="Add New Category" onclick="btnAddCategory_Click" />
             </div>

            </fieldset>
        </div><!--span4-->

        <div class="span8">
            <asp:GridView ID="GridViewCategory" 
                CssClass="table table-bordered table-striped" runat="server" 
                AutoGenerateColumns="False" DataKeyNames="CategoryID"
                DataSourceID="SqlDataSource1" GridLines="None"
                EmptyDataText="There are no data records to display." AllowPaging="True" 
                AllowSorting="True" onrowediting="GridViewCategory_RowEditing">
                <Columns>
                    <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                    <asp:BoundField DataField="CategoryID" HeaderText="CategoryID" Visible="false" ReadOnly="True" SortExpression="CategoryID" />
                    <asp:BoundField DataField="CategoryName" HeaderText="Name" SortExpression="CategoryName" />
                    <asp:BoundField DataField="CategoryDescription" HeaderText="Description"
                        SortExpression="CategoryDescription" />
                    <asp:TemplateField HeaderText="Parent" Visible="false" SortExpression="CategoryParent">
                        <EditItemTemplate>
                            <asp:DropDownList ID="DropDownList1" runat="server" 
                                DataSourceID="SqlDataSource2" DataTextField="CategoryName" 
                                DataValueField="CategoryID" 
                                SelectedValue='<%# Bind("CategoryParent") %>'
                                AppendDataBoundItems="True">
                                <asp:ListItem Value="0">Please Select</asp:ListItem>
                            </asp:DropDownList>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("CategoryParent") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="PostCount" HeaderText="Posts" SortExpression="PostCount" />
                </Columns>
            </asp:GridView>
            <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
                ConnectionString="<%$ ConnectionStrings:CMSConnectionString1 %>" 
                SelectCommand="SELECT DISTINCT [CategoryName], [CategoryID] FROM [CMS_Categories]">
            </asp:SqlDataSource>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CMSConnectionString1 %>"
                DeleteCommand="DELETE FROM [CMS_Categories] WHERE [CategoryID] = @CategoryID"
                InsertCommand="INSERT INTO [CMS_Categories] ([CategoryName], [CategoryDescription], [CategoryParent], [PostCount]) VALUES (@CategoryName, @CategoryDescription, @CategoryParent, @PostCount)"
                ProviderName="<%$ ConnectionStrings:CMSConnectionString1.ProviderName %>" SelectCommand="SELECT [CategoryID], [CategoryName], [CategoryDescription], [CategoryParent], [PostCount] FROM [CMS_Categories]"
                UpdateCommand="UPDATE [CMS_Categories] SET [CategoryName] = @CategoryName, [CategoryDescription] = @CategoryDescription, [CategoryParent] = @CategoryParent, [PostCount] = @PostCount WHERE [CategoryID] = @CategoryID">
                <DeleteParameters>
                    <asp:Parameter Name="CategoryID" Type="Int32" />
                </DeleteParameters>
                <InsertParameters>
                    <asp:Parameter Name="CategoryName" Type="String" />
                    <asp:Parameter Name="CategoryDescription" Type="String" />
                    <asp:Parameter Name="CategoryParent" Type="Int32" />
                    <asp:Parameter Name="PostCount" Type="Int32" />
                </InsertParameters>
                <UpdateParameters>
                    <asp:Parameter Name="CategoryName" Type="String" />
                    <asp:Parameter Name="CategoryDescription" Type="String" />
                    <asp:Parameter Name="CategoryParent" Type="Int32" />
                    <asp:Parameter Name="PostCount" Type="Int32" />
                    <asp:Parameter Name="CategoryID" Type="Int32" />
                </UpdateParameters>
            </asp:SqlDataSource>
        </div>
        </div><!--row-->
    </form>
</asp:Content>
